package cn.pugle.xml;

import org.dom4j.*;
import org.dom4j.io.SAXReader;

import java.io.File;

/**
 * Created by tzp on 2016/12/21.
 */
public class Dom4jTest {
    public static void main(String[] args) throws Exception{
        xPath();
    }

    public static void saxTest() throws DocumentException {
        SAXReader saxReader = new SAXReader();
        Document document = saxReader.read(new File("/Users/tzp/Documents/project/CodeAccumulate/src/main/java/cn/pugle/xml/ModelTrainWorkflow.xml"));
        Element rootElement = document.getRootElement();

        System.out.println(document.nodeCount());//1
        System.out.println(document.getNodeTypeName());//Document
        XPath xPath = DocumentHelper.createXPath("/wkf:workflow/wkf:actions");
        System.out.println(xPath.selectNodes(document));

        System.out.println(rootElement.getName());//workflow
        System.out.println(rootElement.content());

    }

    public static void xPath() throws DocumentException {
        String in = "<InboundMessage><Transaction><Status>Success</Status></Transaction></InboundMessage>";
        Document document = DocumentHelper.parseText(in);
        Node node = document.selectSingleNode("//InboundMessage//Transaction//Status");
        System.out.println(node.getText());
    }
}
